//获取地址栏上的分类id
// 根据 key 找到相应的id值
function getUrlParams (key) {
    var str = location.search.substr(1);
    var arr = str.split('&');
    for(var i=0; i < arr.length; i++) {
        var arr1 = arr[i].split('=');
        if(arr1[0] == key) {
            return arr1[1];
        }
    }
}

var key = getUrlParams('key');
console.log(key);

$.ajax({
    type : 'get',
    url : `/posts/search/${key}`,
    success (res) {
        console.log(res);
        var html = template('searchTpl', { data: res});
        $('#listBox').html(html);
        $('#title').text (res[0].category.title);
    }
})